package com.intel.two.controller.user;


import com.intel.two.pojo.user.User;
import com.intel.two.service.user.UserService;
import com.intel.two.vo.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @Author: Zz
 * @Description: TODO
 * @DateTime: 2022/10/13 14:24
 **/
/*
 *                        .::::.
 *                      .::::::::.
 *                     :::::::::::
 *                  ..:::::::::::'
 *               '::::::::::::'
 *                 .::::::::::
 *            '::::::::::::::..
 *                 ..::::::::::::.
 *               ``::::::::::::::::
 *                ::::``:::::::::'        .:::.
 *               ::::'   ':::::'       .::::::::.
 *             .::::'      ::::     .:::::::'::::.
 *            .:::'       :::::  .:::::::::' ':::::.
 *           .::'        :::::.:::::::::'      ':::::.
 *          .::'         ::::::::::::::'         ``::::.
 *      ...:::           ::::::::::::'              ``::.
 *     ````':.          ':::::::::'                  ::::..
 *                        '.:::::'                    ':'````..
 */
@RestController
@RequestMapping("/api/user/")
public class UserController {

    @Autowired
    private UserService service;

    //添加用户
    @PostMapping("save.do")
    public Result save(@RequestBody User user) {
        return service.save(user);
    }

    //修改信息
    @RequestMapping("update.do")
    public Result update(User user) {

        return service.update(user);
    }

    //登录
    @PostMapping("login.do")
    public Result login(@RequestBody User user,HttpSession session) {
        return service.login(user,session);
    }

    //退出
    @GetMapping("loginout.do")
    public Result loginOut(HttpSession session) {
        session.invalidate();
        return Result.ok("退出成功");
    }
}
